<?php

set_include_path('../');

require_once('show/show.php');
require_once('database/database.php');

require_once('registry.php');

require_once('model/model.php');
require_once('model/column.php');
require_once('model/record.php');
require_once('model/recordset.php');

$db = new database('localhost', 'root', '', 'rephp');
//$db = new database('192.168.210.61', 'root', 'myroot', 'rephp');
$db->debug = true;

registry::getInstance()->db = $db;
registry::getInstance()->models = new stdClass();


class User extends model
{
	var $relations = array(
		array(
			'type' => 'many',
			'model' => 'Post',
			
			'local' => 'id',
			'foreign' => 'user_id',
			
			'as' => 'Posts',
			'recursion' => 3
		)
	);
};

class Post extends model{
	
	var $relations = array(
		array(
			'type' => 'one',
			'model' => 'User',
			
			'local' => 'user_id',
			'foreign' => 'id',
			
			'as' => 'User',
			'recursion' => 0
		)
	);
	
};
$user = new User();
$post = new Post();

$firstUser = $user->findOneBy('id', '1');

show($firstUser);

$newPost = $firstUser->Posts->newPost(
	array(
		'title' => 'test',
		'body' => 'trialari - trialaro'
	)
);

$newPost->save();

showMemoryUsage();

?>